﻿package mortal.game.view.friendBless.view
{
    import Message.Game.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class FriendBlessBallWin extends BaseWindow
    {
        private var _currVol:GTextFiled;
        private var _day:BitmapNumberText;
        private var _hour:BitmapNumberText;
        private var _minutes:BitmapNumberText;
        private var _reward1:GTextFiled;
        private var _reward2:GTextFiled;
        private var _reward3:GTextFiled;
        private var _takeRewardBtn:GLoadingButton;
        private var _ballValue1:GTextFiled;
        private var _ballValue2:GTextFiled;
        private var _ballValue3:GTextFiled;
        private var _hasTake1:GTextFiled;
        private var _hasTake2:GTextFiled;
        private var _hasTake3:GTextFiled;
        private var _tips:GTextFiled;
        private var _ballIcon:GImageBitmap;
        private var _secView:SecTimerView;
        private var _ballValueArr:Array;
        private var _rewardArr:Array;
        private var _hasTakeTipArr:Array;
        private static var _instance:FriendBlessBallWin;

        public function FriendBlessBallWin(param1:ILayer = null)
        {
            this._ballValueArr = [];
            this._rewardArr = [];
            this._hasTakeTipArr = [];
            super(param1);
            setSize(451, 401 - 6);
            title = "好友祝福";
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.FriendBlessBg, 8, 38, this));
            this._currVol = UIFactory.gTextField("99999/99999", 336, (135 - 1), 91, 25, this, GlobalStyle.textFormatPutong.center());
            this._day = UIFactory.bitmapNumberText(78 + 4, 203, "GuildBustlingNum.png", 14, 22, 0, this, 15, BitmapNumberText.Mid);
            this._hour = UIFactory.bitmapNumberText(134 + 3, 203, "GuildBustlingNum.png", 14, 22, 0, this, 15, BitmapNumberText.Mid);
            this._minutes = UIFactory.bitmapNumberText(208, 203, "GuildBustlingNum.png", 14, 22, 0, this, 15, BitmapNumberText.Mid);
            this.pushUIToDisposeVec(UIFactory.gTextField("注意：活动结束后，将不可领取奖励！", 160 - 10 - 41, 236, 260, 25, this, GlobalStyle.textFormatHuang2.setSize(14)));
            this._ballValue1 = UIFactory.gTextField("祝福球达：300     奖励：", 131 - 15 - 32, 261, 175, 25, this, GlobalStyle.textFormatLv.setSize(14));
            this._ballValueArr.push(this._ballValue1);
            this._reward1 = UIFactory.gTextField("xxxxxx", 283 - 15 - 32, 261, 200, 25, this, GlobalStyle.textFormatLv.setSize(14));
            this._rewardArr.push(this._reward1);
            this._hasTake1 = UIFactory.gTextField("(已领取)", 395, 261, 68, 20, this);
            this._hasTake1.visible = false;
            this._hasTakeTipArr.push(this._hasTake1);
            this._ballValue2 = UIFactory.gTextField("祝福球达：600     奖励：", 131 - 15 - 32, 284, 175, 25, this, GlobalStyle.textFormatlan.setSize(14));
            this._ballValueArr.push(this._ballValue2);
            this._reward2 = UIFactory.gTextField("xxxxxx", 283 - 15 - 32, 284, 200, 25, this, GlobalStyle.textFormatlan.setSize(14));
            this._rewardArr.push(this._reward2);
            this._hasTake2 = UIFactory.gTextField("(已领取)", 395, 284, 68, 20, this);
            this._hasTake2.visible = false;
            this._hasTakeTipArr.push(this._hasTake2);
            this._ballValue3 = UIFactory.gTextField("祝福球达：1000     奖励：", 131 - 15 - 32, 309, 175, 25, this, GlobalStyle.textFormatHuang2.setSize(14));
            this._ballValueArr.push(this._ballValue3);
            this._reward3 = UIFactory.gTextField("xxxxxx", 283 - 15 - 32, 309, 200, 25, this, GlobalStyle.textFormatHuang2.setSize(14));
            this._rewardArr.push(this._reward3);
            this._hasTake3 = UIFactory.gTextField("(已领取)", 395, 309, 68, 20, this);
            this._hasTake3.visible = false;
            this._hasTakeTipArr.push(this._hasTake3);
            this._tips = UIFactory.gTextField("", 395 - 15, 370 - 10, 75, 35, this, GlobalStyle.textFormatLv);
            this._tips.htmlText = HTMLUtil.addLink("详细介绍", GlobalStyle.colorLv);
            this._tips.toolTipData = "每次祝福升级的好友和收到祝福，都会增加1点祝福值；好友越多，越容易领取奖励";
            this._tips.reactionTime = 200;
            this._ballIcon = UIFactory.gImageBitmap("", 306 - 45, 131 - 106, this);
            this._secView = UIFactory.secTimeView(Language.getString(30055), 610, 341, 0, 0, null);
            this._takeRewardBtn = UIFactory.gLoadingButton(ResFileConst.DailyRewardBtn, 170, 351, 103, 40, this);
            this._takeRewardBtn.configEventListener(MouseEvent.CLICK, this.onTakeRewardHandler);
            this.updateAll();
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.FriendBlessCongratulateInfo, this.onCongratulateInfoUpdate);
            return;
        }// end function

        private function removeListeners() : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.FriendBlessCongratulateInfo, this.onCongratulateInfoUpdate);
            return;
        }// end function

        private function updateAll() : void
        {
            this.updateBallVol();
            this.updateLeftTime();
            this.updateRewardInfo();
            return;
        }// end function

        private function onCongratulateInfoUpdate(param1:Object) : void
        {
            this.updateAll();
            return;
        }// end function

        private function updateBallVol() : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            var _loc_1:* = Cache.instance.friendBless.sCongratulateInfo;
            var _loc_2:* = QuestionCopyConfig.instance().getRewardInfoByType(5);
            for each (_loc_6 in _loc_2)
            {
                
                if (_loc_1.congratulateValue >= _loc_6.scoreMin && _loc_1.congratulateValue <= _loc_6.scoreMax)
                {
                    _loc_3 = _loc_6.scoreMax as int;
                    _loc_5 = _loc_6;
                }
                _loc_4 = _loc_6.scoreMax > _loc_4 ? (_loc_6.scoreMax) : (_loc_4);
            }
            if (_loc_3 == 0)
            {
                _loc_3 = _loc_4;
            }
            if (_loc_5)
            {
                switch(_loc_5.scoreMax)
                {
                    case 10:
                    {
                        this._ballIcon.imgUrl = ImagesConst.FriendBlessBallWin_Lv;
                        break;
                    }
                    case 50:
                    {
                        this._ballIcon.imgUrl = ImagesConst.FriendBlessBallWin_Lan;
                        break;
                    }
                    case 100:
                    {
                        this._ballIcon.imgUrl = ImagesConst.FriendBlessBallWin_Zi;
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            this._currVol.text = _loc_1.congratulateValue + "/" + _loc_4;
            return;
        }// end function

        private function updateLeftTime() : void
        {
            var _loc_5:String = null;
            var _loc_6:String = null;
            var _loc_7:String = null;
            var _loc_1:* = ClockManager.instance.nowDate;
            var _loc_2:* = new Date(ClockManager.instance.serverOpenDate.time);
            var _loc_3:* = new Date(_loc_2.time + 3 * 24 * 3600 * 1000);
            var _loc_4:* = _loc_3.time - _loc_1.time;
            this._secView.stop();
            if (_loc_4 > 0)
            {
                this._secView.setLeftTime(_loc_4 / 1000);
                _loc_5 = this._secView.secTimerViewData.dd();
                _loc_6 = this._secView.secTimerViewData.hh();
                _loc_7 = this._secView.secTimerViewData.mm();
                this._day.text = "" + _loc_5;
                this._hour.text = "" + _loc_6;
                this._minutes.text = "" + _loc_7;
            }
            else
            {
                this._day.text = "00";
                this._hour.text = "00";
                this._minutes.text = "00";
            }
            return;
        }// end function

        private function updateRewardInfo() : void
        {
            var _loc_1:* = QuestionCopyConfig.instance().getRewardInfoByType(5);
            _loc_1.sort(this.sortOnCode);
            this._ballValue1.text = "祝福球达：" + _loc_1[0].scoreMax + "     奖励：";
            this._ballValue2.text = "祝福球达：" + _loc_1[1].scoreMax + "     奖励：";
            this._ballValue3.text = "祝福球达：" + _loc_1[2].scoreMax + "   奖励：";
            this._reward1.text = " 经验" + _loc_1[0].experFixed + "  金币" + _loc_1[0].vitalEnergy;
            this._reward2.text = " 经验" + _loc_1[1].experFixed + "  金币" + _loc_1[1].vitalEnergy;
            this._reward3.text = " 绑定钻石" + _loc_1[2].bindGold + "  金币" + _loc_1[2].vitalEnergy;
            var _loc_2:* = Cache.instance.friendBless.sCongratulateInfo;
            if (_loc_2)
            {
                this.updateRewardTakeState(_loc_2.hadGain);
            }
            return;
        }// end function

        private function updateRewardTakeState(param1:int) : void
        {
            var _loc_2:int = 0;
            if (param1 == 0)
            {
                _loc_2 = 0;
                while (_loc_2 < 3)
                {
                    
                    this._hasTakeTipArr[_loc_2].visible = false;
                    _loc_2++;
                }
            }
            else
            {
                _loc_2 = 0;
                while (_loc_2 < param1)
                {
                    
                    this._hasTakeTipArr[_loc_2].visible = true;
                    _loc_2++;
                }
            }
            return;
        }// end function

        private function sortOnCode(param1:Object, param2:Object) : Number
        {
            if (param1.code < param2.code)
            {
                return -1;
            }
            if (param1.code > param2.code)
            {
                return 1;
            }
            return 0;
        }// end function

        private function onTakeRewardHandler(event:MouseEvent) : void
        {
            GameProxy.friend.getCongratulateRewards();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._currVol.dispose();
            this._currVol = null;
            this._day.dispose();
            this._day = null;
            this._hour.dispose();
            this._hour = null;
            this._minutes.dispose();
            this._minutes = null;
            this._reward1.dispose();
            this._reward1 = null;
            this._reward2.dispose();
            this._reward2 = null;
            this._reward3.dispose();
            this._reward3 = null;
            this._takeRewardBtn.dispose();
            this._takeRewardBtn = null;
            this._ballValue1.dispose();
            this._ballValue1 = null;
            this._ballValue2.dispose();
            this._ballValue2 = null;
            this._ballValue3.dispose();
            this._ballValue3 = null;
            this._tips.dispose();
            this._tips = null;
            this._ballIcon.dispose();
            this._ballIcon = null;
            this._hasTake1.dispose();
            this._hasTake1 = null;
            this._hasTake2.dispose();
            this._hasTake2 = null;
            this._hasTake3.dispose();
            this._hasTake3 = null;
            this._secView.dispose();
            this._secView = null;
            this._ballValueArr.length = 0;
            this._rewardArr.length = 0;
            this._hasTakeTipArr.length = 0;
            this.removeListeners();
            return;
        }// end function

        public static function get instance() : FriendBlessBallWin
        {
            if (_instance == null)
            {
                _instance = new FriendBlessBallWin;
            }
            return _instance;
        }// end function

    }
}
